#include "dtartist.h"

DtArtist::DtArtist()
{
}

DtArtist::DtArtist(const QString & name, const int id, const bool heart)
{
    this->id = id;
    this->name = name;
    this->heart.setHeart(heart);
}

DtArtist::DtArtist(const DtArtist &artist)
{
    id = artist.id;
    name = artist.name;
    heart.setHeart(artist.heart.isHeart());
}

DtArtist::~DtArtist()
{

}

QDebug operator<<(QDebug dbg, const DtArtist &artist)
{
    dbg.space() << "Artist" << artist.getId() << artist.getName();
    return dbg.space();
}

int DtArtist::getNbAttr() const
{
    return DtArtist::NbAttr;
}

QVariant DtArtist::getAttr(const int nb)
{
    switch (nb) {
    case DtArtist::Name:
        return getName();
        break;
    case DtArtist::Heart:
        return getHeart();
        break;
    case DtArtist::Id:
        return getId();
    default:
        break;
    }
    return QVariant();
}

void DtArtist::clicked(const int section)
{
    switch (section) {
    case DtArtist::Play: /* Play */
        playSvg.setPlay(!playSvg.isPlay());
        break;
    case DtArtist::Add: /* Ajouter */
        break;
    case DtArtist::Name: /* Titre de l'album */
        break;
    case DtArtist::Heart: /* Heart */
        heart.setHeart(!heart.isHeart());
        DbArtist::setHeart(*this);
        break;
    default:
        break;
    }
}

QVariant DtArtist::getToolTip() const
{
    QString n;
    n.setNum(lAlbum.size());
    return name + "\nPosséde : " + n + " Albums";
}

DtArtist * DtArtist::findById(QList<DtArtist *> & sArtist, const int id)
{
    for(QList<DtArtist *>::Iterator it = sArtist.begin();
        it != sArtist.end(); it++)
    {
        if((*it)->getId() == id)
            return (*it);
    }
    return NULL;
}

void DtArtist::addTrack(DtTrack *track)
{
    if(!lTrack.contains(track))
        lTrack.append(track);
}

void DtArtist::addAlbum(DtAlbum *album)
{
    if(!lAlbum.contains(album))
        lAlbum.append(album);
}

void DtArtist::addGenre(DtGenre *genre)
{
    if(!lGenre.contains(genre))
        lGenre.append(genre);
}

QList<DtAlbum *> &DtArtist::getAlbums()
{
    return lAlbum;
}

QList<DtTrack *> &DtArtist::getTracks()
{
    return lTrack;
}

QList<DtGenre *> &DtArtist::getGenres()
{
    return lGenre;
}
